//
//  GraduatedScaleViewController.m
//  分享demo
//
//  Created by pc-chtypd056 on 2018/8/6.
//  Copyright © 2018年 CTL. All rights reserved.
//

#import "GraduatedScaleViewController.h"
#import "TTScrollRulerView.h"

@interface GraduatedScaleViewController ()<rulerDelegate>
{
    NSInteger _value;
}
@property (nonatomic, strong) UIView *backgroundView;
/** 关闭按钮 */
@property (nonatomic, strong) UIButton *closeButton;
/** <#注释说明#> */
@property (nonatomic, copy) ScaleBlock completeBlock;
@end

@implementation GraduatedScaleViewController

+ (instancetype)graduatedScaleWithBlock:(ScaleBlock)complete{
    
    GraduatedScaleViewController *scaleVC = [[GraduatedScaleViewController alloc]init];
    scaleVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
    scaleVC.completeBlock = complete;
    return scaleVC;
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    
    self.backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, ScreenHEIGH-(ScreenHEIGH/2)-(ScreenHEIGH/6), ScreenWIDTH, ScreenHEIGH/2+(ScreenHEIGH/6))];
    self.backgroundView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.backgroundView];
    
    self.closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.closeButton setTitle:@"关闭" forState:UIControlStateNormal];
    [self.closeButton addTarget:self action:@selector(closeButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    self.closeButton.frame = CGRectMake(ScreenWIDTH-60, 10, 50, 30);
    self.closeButton.backgroundColor = [UIColor redColor];
    [self.backgroundView addSubview:self.closeButton];
    
    TTScrollRulerView *rulerClassic = [[TTScrollRulerView alloc] initWithFrame:CGRectMake(0, self.closeButton.frame.size.height+self.closeButton.frame.origin.y+10, ScreenWIDTH, 100)];
    [self.backgroundView addSubview:rulerClassic];
    rulerClassic.rulerDelegate = self;
    rulerClassic.lockDefault = 200;
    rulerClassic.lockMax = 500;
    //在执行此方法前，可先设定参数：最小值，最大值，横向，纵向等等  ------若不设定，则按照默认值绘制
    [rulerClassic classicRuler];
    [rulerClassic customRulerWithLineColor:customColorMake(122, 122, 122) NumColor:[UIColor blackColor] scrollEnable:YES];
}

- (void)closeButtonEvent:(UIButton *)button{
    if (_completeBlock) {
        _completeBlock(_value);
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)rulerWith:(NSInteger)value{
    NSLog(@"value:%ld",(long)value);
    _value= value;
}

@end
